package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.ExpertListBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 专家列表适配
 * Created by sy on 2019/3/20.
 */

public class ExpertListAdapter extends BaseQuickAdapter<ExpertListBean.ItemsBean,ExpertListAdapter.ViewHolder> {

    public ExpertListAdapter() {
        super(R.layout.item_expert_list);
    }

    @Override
    protected void convert(ExpertListAdapter.ViewHolder helper, ExpertListBean.ItemsBean item) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                .error(R.mipmap.ic_default_small)	//加载错误之后的错误图
//                .override(88,87)	//指定图片的尺寸
                .centerCrop();//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
        Glide.with(mContext)
                .load(item.icon)
                .apply(options)
                .into(helper.iv_img);

        helper.tv_name.setText(item.name);
        if (item.free) {//	状态 true空闲 false忙碌
            helper.tv_state.setText("空闲");
            helper.tv_state.setTextColor(ContextCompat.getColor(mContext,R.color.expert_idle_color));
            Drawable drawableLeft = mContext.getResources().getDrawable(R.drawable.shape_idle);
            helper.tv_state.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,null, null, null);
        } else {
            helper.tv_state.setText("忙碌");
            helper.tv_state.setTextColor(ContextCompat.getColor(mContext,R.color.expert_busy_color));
            Drawable drawableLeft = mContext.getResources().getDrawable(R.drawable.shape_busy);
            helper.tv_state.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,null, null, null);
        }
        helper.tv_info.setText(item.postName);
        helper.addOnClickListener(R.id.tv_remote);


    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.iv_img)
        ImageView iv_img;
        @BindView(R.id.tv_name)
        TextView tv_name;
        @BindView(R.id.tv_state)
        TextView tv_state;
        @BindView(R.id.tv_info)
        TextView tv_info;
        @BindView(R.id.tv_remote)
        TextView tv_remote;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
